#include "ohos_video_source_adapter.h"
#include "absl/types/optional.h"
#include "rtc_base/logging.h"

namespace ohoswebrtc {

rtc::scoped_refptr<OHOSVideoTrackSourceAdapter> OHOSVideoTrackSourceAdapter::Create(bool is_screencast) {
  return rtc::make_ref_counted<OHOSVideoTrackSourceAdapter>(is_screencast);
}

OHOSVideoTrackSourceAdapter::OHOSVideoTrackSourceAdapter() : OHOSVideoTrackSourceAdapter(false) {
  
}

OHOSVideoTrackSourceAdapter::OHOSVideoTrackSourceAdapter(bool is_screencast)
    : AdaptedVideoTrackSource(/* required resolution alignment */ 2),
      is_screencast_(is_screencast) {}

OHOSVideoTrackSourceAdapter::~OHOSVideoTrackSourceAdapter() {
  RTC_LOG(LS_INFO) << __FUNCTION__ << ": Dtor";
}

bool OHOSVideoTrackSourceAdapter::is_screencast() const {
  return is_screencast_;
}

absl::optional<bool> OHOSVideoTrackSourceAdapter::needs_denoising() const {
  return false;
}

webrtc::MediaSourceInterface::SourceState OHOSVideoTrackSourceAdapter::state() const {
  return webrtc::MediaSourceInterface::SourceState::kLive;
}

bool OHOSVideoTrackSourceAdapter::remote() const {
  return false;
}

void OHOSVideoTrackSourceAdapter::OnOutputFormatRequest(int width, int height, int fps) {
  cricket::VideoFormat format(width, height, cricket::VideoFormat::FpsToInterval(fps), 0);
  video_adapter()->OnOutputFormatRequest(format);
}

void OHOSVideoTrackSourceAdapter::OnFrameCaptured(const webrtc::VideoFrame &frame) {
  OnFrame(frame);
}

}  // namespace webrtc
